/*
 * NyuString.hpp
 *
 *  Created on: 2010/05/23
 *      Author: mitsu
 */

#ifndef NYUSTRING_HPP_
#define NYUSTRING_HPP_

#include "NyuObject.hpp"

class NyuString : public NyuObject {
public:
    NyuString(unsigned int hash);

    virtual NyuString* to_str(NyuContext* c);
    virtual NyuValue opEq(NyuValue other, NyuContext* c, bool is_tail = false);
    virtual NyuValue revEqStr(const char* str, NyuContext* c, bool is_tail = false);
    virtual const char* strval() const = 0;
    virtual unsigned int hash() const;

    // StrPoolから呼ばれるやつ
    virtual void dispose() = 0;

    static unsigned int calcHash(const char* str);
    static NyuValue fromCharCodeFunc(NyuContext* c);

protected:
    unsigned int hash_;
};

class NyuImmutableString : public NyuString {
public:
    NyuImmutableString(char* strval);
    NyuImmutableString(char* strval, unsigned int hash);
    virtual ~NyuImmutableString();

    virtual const char* strval() const;
    virtual void dispose();

private:
    char* strval_;
};

class NyuStaticString : public NyuString {
public:
    NyuStaticString(const char* strval);

    virtual const char* strval() const;
    virtual void dispose();

public:
    static NyuStaticString PROTO;  // __proto__
    static NyuStaticString OBJECT; // Object
    static NyuStaticString STRING; // String
    static NyuStaticString FROM_CHAR_CODE; // fromCharCode
    static NyuStaticString RANGE;  // Range
    static NyuStaticString START;  // start
    static NyuStaticString END;    // end
    static NyuStaticString STEP;   // step
    static NyuStaticString BORDER; // border
    static NyuStaticString EACH;   // each
    static NyuStaticString ARRAY;  // Array
    static NyuStaticString LENGTH; // length
    static NyuStaticString PUSH;   // push
    static NyuStaticString POP;    // pop

    static NyuStaticString INT;    // __int__

    static NyuStaticString NOT;    // __not__
    static NyuStaticString INVERT; // __invert__
    static NyuStaticString POS;    // __pos__
    static NyuStaticString NEG;    // __neg__
    static NyuStaticString INCR;   // __incr__
    static NyuStaticString DECR;   // __decr__
    static NyuStaticString POST_INCR; // __postincr__
    static NyuStaticString POST_DECR; // __postdecr__
    static NyuStaticString ADD;    // __add__
    static NyuStaticString SUB;    // __sub__
    static NyuStaticString MUL;    // __mul__
    static NyuStaticString DIV;    // __div__
    static NyuStaticString MOD;    // __mod__
    static NyuStaticString CALL;   // __call__

private:
    const char* strval_;
};

#endif /* NYUSTRING_HPP_ */
